<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <title>会员管理</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
    <style type="text/css">
			table th{
				text-align: center;
	            white-space: nowrap;
	        }
			table td{
				text-align: center;
	            white-space: nowrap;
	        }
		    table{
		         empty-cells:show; 
		         border-collapse: collapse;
		         margin:0 auto;
		    }
 			.col-lg-9 {
			    width: 100%;
			}
			.pcc{
				width: 110px;
				height: 34px;
			}
			input{
				text-indent:10px;
				width: 80%;
				border-radius:5px;
			}
		</style>
		
</head>
<body>
<div id="wrapper" class="row">
		<div class="col-lg-12">
			<h1 class="page-header">余额转换</h1>
		</div>
	<!-- 搜索框 -->
		<div class="title-top col-lg-11">
		<div class="search-input">
			<label class="search-label">会员手机号：</label><input type="text" id="sPhone" value="" placeholder="手机号" class="form-control search-input width200" maxlength="21">
			<label class="search-label">会员卡号：</label><input type="text" id="sCard" value="" placeholder="请输入会员卡号" class="form-control search-input width200" maxlength="21">
			<label class="search-label">公司：</label>
			<div class="search-input">
				<select name="sSeller" id="sSeller" class="form-control" >
					<c:if test="${fn:length(sellerList) > 0}">
						<option value="">请选择公司</option>
						<c:forEach items="${sellerList}" var="seller" varStatus="s">
							<option value="${seller.sellerId }">${seller.sellerName }</option>	
						</c:forEach>
					</c:if>
				</select>
			</div>
			<label class="search-label">分公司：</label>
			<div class="search-input">
				<select name="sStore" id="sStore" class="form-control" >
					<option value="">请选择分公司</option>
				</select>
			</div>
			<label class="search-label">营业部：</label>
			<div class="search-input">
				<select name="sDao" id="sDao" class="form-control" >
					<option value="">请选择营业部</option>
				</select>
			</div>
		</div>
		<div class="search-input">
		<label class="search-label">等级：</label>
			<select id="sTaici" class="selectpicker" multiple="multiple" data-width="150">
				<option value="1">会员</option>
				<option value="2">黄金</option>
				<option value="3">白金</option>
				<option value="4">经纪人</option>
				<option value="5">营业部</option>
				<option value="6">分公司</option>
			</select>
		</div>
		<div class="search-input">
			<label class="search-label">审核：</label>
			<select id="sState" class="selectpicker" multiple="multiple" data-width="150">
				<option value="1">待审核</option>
				<option value="2">驳回</option>
				<option value="3">已审核</option>
			</select>
		</div>
		<button class="btn btn-success search-btn" onclick="query();">确定</button>
		<button class="btn btn-success search-btn" onclick="reset();">重置</button>
		<div class="clearfix">
			<button type="button" class="btn btn-default pull-left" title="刷新" 
					onclick="window.location.reload();">
					<i class="fa fa-refresh"></i> 刷新
			</button>
		</div>
		<div class="col-lg-12">
			<div class="text-muted single-line-text pull-left">共 <font color="#428bca" id="dataCount">0</font>条记录</div>
			<div class="text-muted single-line-text pull-left">
				统计:
				<span class="m-l-5"> 
					总兑换金额<font color="#428bca" id="total">0.00</font>元
				</span>
				<span class="m-l-5"> 
					已转换金额<font color="#428bca" id="accept">0.00</font>元
				</span>
				<span class="m-l-5"> 
					驳回金额<font color="#428bca" id="cancel">0.00</font>元
				</span>
				<span class="m-l-5"> 
					总惠券<font color="#428bca" id="jypoint">0.00</font>元
				</span>
			</div>
		</div>
			<div class="table-responsive panel panel-default" >
				<table id="dataTable" class="table table-hover table-bordered" style="overflow:scroll;">
					<thead>
						<tr>
							<th width="150px;">操作</th>
							<th width="120px;">操作人</th>
							<th width="100px;">审核状态</th>
							<th width="200px;">单据号码</th>
							<th width="100px;">兑换余额/元</th>
							<th width="130px;">消耗</th>
							<th width="150px;">会员卡号</th>
							<th width="80px;">会员姓名</th>
							<th width="130px;">会员手机号</th>
							<th width="210px;">所属公司</th>
							<th width="120px;">所属分公司</th>
							<th width="80px;">营业部</th>
							<th width="80px;">等级</th>

						</tr>
					</thead>
					<tbody id="dataList"></tbody>
				</table>
			</div>
				<div class="col-lg-12">
					<div class = "pull-right">
						<div class="text-muted  pull-left" style="margin-top:20px; margin-right:18px;">
							<select id="pageSize" name="pageSize" class="selectpicker" data-width="100" onchange="query()" >
								<option value="10" selected = "selected">10条/页</option>
								<option value="15">15条/页</option>
								<option value="20">20条/页</option>
								<option value="50">50条/页</option>
								<option value="100">100条/页</option>
		    				</select>
						</div>
		        		<ul id="dataPagination" class="pagination-sm pull-right"></ul>
		        	</div>
	        	</div>
		</div>
	</div>
<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<!-- 异步加载下一页数据后，用模板渲染 -->
<script src="${BASE_PATH}/static/js/PCASClass.js" type="text/javascript"></script>
<script type="text/html" id="dataTpl">
		{{each list as item}}
				 <tr id="item{{item.tmId}}" data-id="{{item.tmId}}">
					{{if item.tmState==1}}
						<td>
							<a href="javascript:doPass('{{item.tmId}}');"><span class="btn">通过</span></a>
							<a href="javascript:doReturn('{{item.tmId}}','{{item.tmJypoint}}');"><span class="btn">驳回</span></a>
						</td>
					{{else if item.tmState==2}}
						<td>
							<a href="javascript:return false;" style="opacity: 0.3"><span class="btn">通过</span></a>
							<a href="javascript:return false;" style="opacity: 0.3"><span class="btn">驳回</span></a>
						</td>
					{{else if item.tmState==3}}
						<td>
							<a href="javascript:return false;" style="opacity: 0.3"><span class="btn">通过</span></a>
							<a href="javascript:return false;" style="opacity: 0.3"><span class="btn">驳回</span></a>
						</td>
					{{/if}}
					<td>
						{{if item.changeName}}{{item.changeName}}{{/if}}
						{{if !item.changeName}}待操作{{/if}}
					</td>
					<td>{{item.tmState | flagTransform:1,'待审核',2,'驳回',3,'成功'}}</td>
					<td>{{item.tmOrderNo}}</td>
					<td>{{item.tmMoney}}</td>
					<td>{{item.tmJypoint}}</td>
				 	<td>
						<a href="javascript:showUser('{{item.id}}');"><font color="#40a9ff" id="dataCount">{{if item.card}}{{item.card }}{{/if}}
								{{if !item.card}}--{{/if}}
							</font>
						</a>
					</td>
					<td>{{item.name}}</td>
					<td>{{item.phone}}</td>
					<td>
						{{if item.toBossThreeId}}{{item.sellerName }}{{/if}}
						{{if !item.toBossThreeId}}--{{/if}}
					</td>
					<td>
						{{if item.toBossTwoId}}{{item.storeName }}{{/if}}
						{{if !item.toBossTwoId}}--{{/if}}
					</td>
					<td>
						{{if item.toBossOneId}}{{item.trueName}}{{/if}}
						{{if !item.toBossOneId}}--{{/if}}
					</td>
					<td>{{item.taici | flagTransform:1,'会员',2,'黄金',3,'白金',4,'经纪人',5,'营业部',6,'分公司',7,'公司'}}</td>

					
				</tr>
		{{/each}}
</script>
<script type="text/javascript">

var dataPaginator;
$(query);
function query(){
	var pageSize=$("#pageSize").val();
	 var phone=$("#sPhone").val(),card=$("#sCard").val();
	 seller=$("#sSeller").val(),store=$("#sStore").val(),dao=$("#sDao").val();
	 var taici=$("#sTaici").val(),state=$("#sState").val();
	 var taicis="",states="";
		if(taici !=null && taici !="" && taici !=undefined){
			taicis=taici.join("','");
		}
		if(state !=null && state !="" && state !=undefined){
			states=state.join("','");
		}
	 
	 var params = {
		pageSize:pageSize,
		phone:phone,
		card:card,
		seller:seller,
		store:store,
		dao:dao,
		taici:taicis,
		state:states,
	};
	if(dataPaginator){
		dataPaginator.destroy();
	}
	dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/change/money/page",params,function(result){
		//设置显示最新的数据数量
		$("#dataCount").html(result.object.totalRow);
		//根据模板渲染数据并填充
		$("#dataList").empty().append(template("dataTpl",result.object));
		findTotal();
	});
}
/**
 * 统计总所需积分和总现金价格
 */
function findTotal(){
var pointType=$("#pointType").val(),sStoreId = $("#sStoreId").val();
	
	var params = {
		pageSize:10,
		orderNum:$("#sOrderNum").val(),
		beginDate:$("#sBeginDate").val(),
		endDate:$("#sEndDate").val(),
		tel:$("#sTel").val(),
		state:$("#sState").val(),
		sType:$("#sType").val(),
		sStoreId:sStoreId,
		pointType:pointType
	};
	$.post("${BASE_PATH}/change/money/findTotal",params,function(result){
		if(result.flag==0){
			//$("#payPoint").text(result.object.payPoint);//总所需积分
			$("#total").text(result.object.total.toFixed(2));//总累计现金
			$("#accept").text(result.object.accept.toFixed(2));//总通过
			$("#cancel").text(result.object.cancel.toFixed(2));//总驳回现金
			$("#jypoint").text(result.object.jypoint.toFixed(2));//总惠券
		}else{
			Kit.alert("操作失败");return;
		}
	});
}


function reset(){
	$("#sPhone").val("");$("#sCard").val("");$("#sBeginDate").val("");$("#sEndDate").val("");$("#beginDate").val("");$("#endDate").val("");
	$("#sSeller").val("");$("#sSeller").trigger("change");$("#sStore").val("");$("#sStore").trigger("change");$("#sDao").val("");$("#sDao").trigger("change");
	$("#sTaici").val("");$("#sTaici").trigger("change");$("#sState").val("");$("#sState").trigger("change");
	 $("#sStore").selectpicker("refresh"); $("#sDao").selectpicker("refresh");$("#sState").selectpicker("refresh"); $("#sTaici").selectpicker("refresh");
}


var showDialog;
function showUser(id){
	showDialog = Kit.dialog("会员详情信息","${BASE_PATH}/bus/user/detail/"+id,{size:'size-wide',closable:true}).open();
}
function onEditSuccess(newObject){
	console.log(newObject);
	$("#item"+newObject.tmId).replaceWith(template("dataTpl",{"list":[newObject]}));
}

function doPass(id){
	Kit.confirm("提示","确定要审核申请吗？",function(ref){
		$.post("${BASE_PATH}/change/money/doPass",{'id':id},function(result){
			if(result.flag==0){
				onEditSuccess(result.object);
			}else{
				Kit.alert("操作失败");return;
			}
		});
	});
}
function doReturn(id,tmJypoint){
	Kit.confirm("提示","确定要驳回审核申请吗？",function(){
		$.post("${BASE_PATH}/change/money/doReturn",{'id':id,'tmJypoint':tmJypoint},function(result){
			if(result.flag==0){
				onEditSuccess(result.object);
			}else{
				Kit.alert("操作失败");return;
			}
		});
	});
}
/* function doExcel(){
	 var phone=$("#sPhone").val(),card=$("#sCard").val();
	 var beginDate=$("#beginDate").val(),endDate=$("#endDate").val(),store=$("#sStore").val(),dao=$("#sDao").val();
	 var taici=$("#sTaici").val(),state=$("#sState").val();
	var province=$("#Sprovince").val(),city=$("#Scity").val(),area=$("#Sarea").val();
	 //地址筛选拼接
// 	 var address=province+city+area; 
	 var taicis="",states="";
		if(taici !=null && taici !="" && taici !=undefined){
			taicis=taici.join("','");
		}
		if(state !=null && state !="" && state !=undefined){
			states=state.join("','");
		}
	window.location.href="${BASE_PATH}/bus/user/doExcel?phone="+phone+"&beginDate="+beginDate+"&endDate="
			+endDate+"&card="+card+"&sBeginDate="+sBeginDate+"&sEndDate="+sEndDate+"&store="+store+"&dao="
			+dao+"&taici="+taicis+"&state="+states;
} */


//异步取分公司
$("#sSeller").change(function(){
	sSeller=$("#sSeller").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/bus/user/chooseStore",
           data: {"seller" : sSeller},
           dataType: "json",
           traditional: true,
           success: function(data){
			$("#sStore").empty(); 
			$("#sStore").append("<option value=''>请选择分公司</option>");
			for(var i=0; i<data.object.length;i++){
				$("#sStore").append("<option value='"+data.object[i].storeid+"'>"+data.object[i].title+"</option>");
               }
              // $("#toBossOneId").selectpicker("refresh");	
           }
       });
    });
$("#sStore").change(function(){
	sStore=$("#sStore").val();
	  $.ajax({
           type: "POST",
           url: "${BASE_PATH}/bus/user/chooseDao",
           data: {"store" : sStore},
           dataType: "json",
           traditional: true,
           success: function(data){
          	   $("#sDao").empty(); 
               $("#sDao").append("<option value=''>请选择营业部</option>");
               for(var i=0; i<data.object.length;i++){
              	 $("#sDao").append("<option value='"+data.object[i].trueName+"'>"+data.object[i].trueName+"</option>");
               }
              	//$("#sDao").selectpicker("refresh");
           }
       });
    });

</script>
</body>
</html>